def vigenere_encrypt(text, key):
    encrypted_text = ""
    key_index = 0

    for char in text:
        if char.isalpha():
            # 确定密钥字符和偏移量
            key_char = key[key_index % len(key)].upper()
            key_offset = ord(key_char) - ord('A')

            # 加密字符
            start = ord('A') if char.isupper() else ord('a')
            encrypted_char = chr((ord(char) - start + key_offset) % 26 + start)
            encrypted_text += encrypted_char

            # 移动到下一个密钥字符
            key_index += 1
        else:
            # 非字母字符保持不变
            encrypted_text += char

    return encrypted_text


def vigenere_decrypt(text, key):
    decrypted_text = ""
    key_index = 0

    for char in text:
        if char.isalpha():
            # 确定密钥字符和偏移量
            key_char = key[key_index % len(key)].upper()
            key_offset = ord(key_char) - ord('A')

            # 解密字符
            start = ord('A') if char.isupper() else ord('a')
            decrypted_char = chr((ord(char) - start - key_offset) % 26 + start)
            decrypted_text += decrypted_char

            # 移动到下一个密钥字符
            key_index += 1
        else:
            # 非字母字符保持不变
            decrypted_text += char

    return decrypted_text